/**
 * 学生类
 * 包含学生的基本信息和各科成绩
 */
public class Student {
    private String studentId; // 学号
    private String name; // 姓名
    private String className; // 班级名称
    private double[] courseScores; // 各科成绩数组
    private double comprehensiveScore; // 综合测评成绩（加权平均分）
    private int rank; // 排名
    private String scholarship; // 奖学金等级（一等奖、二等奖、三等奖、无）

    /**
     * 构造方法
     * 
     * @param studentId    学号
     * @param name         姓名
     * @param className    班级名称
     * @param courseScores 各科成绩数组
     */
    public Student(String studentId, String name, String className, double[] courseScores) {
        this.studentId = studentId;
        this.name = name;
        this.className = className;
        this.courseScores = courseScores.clone();
        this.comprehensiveScore = calculateComprehensiveScore();
        this.rank = 0;
        this.scholarship = "无";
    }

    /**
     * 计算综合测评成绩（这里使用简单平均分，实际可以根据权重计算）
     * 
     * @return 综合测评成绩
     */
    private double calculateComprehensiveScore() {
        if (courseScores == null || courseScores.length == 0) {
            return 0.0;
        }
        double sum = 0.0;
        for (double score : courseScores) {
            sum += score;
        }
        return sum / courseScores.length;
    }

    // Getter和Setter方法
    public String getStudentId() {
        return studentId;
    }

    public String getName() {
        return name;
    }

    public String getClassName() {
        return className;
    }

    public double[] getCourseScores() {
        return courseScores.clone();
    }

    public double getComprehensiveScore() {
        return comprehensiveScore;
    }

    public int getRank() {
        return rank;
    }

    public void setRank(int rank) {
        this.rank = rank;
    }

    public String getScholarship() {
        return scholarship;
    }

    public void setScholarship(String scholarship) {
        this.scholarship = scholarship;
    }

    /**
     * 显示学生详细信息
     * 
     * @return 学生信息字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("学号: %-8s 姓名: %-6s 班级: %-8s ", studentId, name, className));
        sb.append("各科成绩: [");
        for (int i = 0; i < courseScores.length; i++) {
            sb.append(String.format("%.2f", courseScores[i]));
            if (i < courseScores.length - 1) {
                sb.append(", ");
            }
        }
        sb.append("] ");
        sb.append(String.format("综合成绩: %.2f 排名: %d 奖学金: %s",
                comprehensiveScore, rank, scholarship));
        return sb.toString();
    }
}

